var app = getApp();

Page({
    data: {
        menu2: [ "线上活动", "线下活动" ],
        menu3: [ "今天", "明天", "后天" ],
        luntext: [ "分类", "类型", "日期" ],
        activeIndex: 7,
        zheceng: !0,
        page: 1,
        activity_list: [],
        type_id: "",
        activity_type: "",
        start_time: "",
        route: "../classification/classification"
    },
    onLoad: function(t) {
        console.log(t), app.setNavigationBarColor(this);
        var a = this, e = wx.getStorageSync("db_tab"), i = (a.data.route, app.contains(e, "../classification/classification"));
        console.log(i), 0 != i && (e[i].color = "selsects", e[i].img = e[i].icon1, console.log(e)), 
        null != t.type_id && a.setData({
            type_id: t.type_id
        }), null != t.activity_type && a.setData({
            activity_type: t.activity_type
        }), null != t.start_time && (a.setData({
            start_time: t.start_time
        }), a.start_time()), a.setData({
            yes: i,
            db_tab: e
        }), app.util.request({
            url: "entry/wxapp/url",
            cachetime: "0",
            success: function(t) {
                console.log("这是网址"), console.log(t), wx.setStorageSync("url", t.data), a.setData({
                    url: t.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/typeList",
            cachetime: "0",
            success: function(t) {
                console.log("这是分类"), console.log(t), a.setData({
                    typeList: t.data
                }), a.activity();
            }
        });
    },
    activity: function(t) {
        var i = this;
        console.log(i.data);
        var c = i.data.typeList, n = i.data.today, o = i.data.page;
        console.log("当前的页数为" + o);
        var s = i.data.activity_list, r = [], a = i.data.type_id, e = i.data.activity_type, l = i.data.start_time;
        if (console.log("分类id" + a), console.log("活动类型" + e), console.log("开始时间" + l), "" == wx.getStorageSync("city") || null == wx.getStorageSync("city")) var y = i.data.city; else y = wx.getStorageSync("city");
        console.log("当前选择的城市为" + y);
        n = app.today_time();
        app.util.request({
            url: "entry/wxapp/ActivityList",
            cachetime: "0",
            data: {
                page: o,
                cityname: y,
                start_time: l,
                activity_type: e,
                type_id: a
            },
            success: function(t) {
                if (console.log("这是活动列表"), console.log(t), 0 < t.data.length) {
                    for (var a in s = s.concat(t.data), r = t.data, r) {
                        for (var e in r[a].end_time = app.ormatDate(r[a].end_time), r[a].start_time = app.ormatDate(r[a].start_time).slice(0, 16), 
                        1 == r[a].is_close && n < r[a].end_time ? n >= r[a].start_time ? r[a].activity_over = 3 : r[a].activity_over = 1 : r[a].activity_over = 2, 
                        c) r[a].type_id == c[e].id && (r[a].type_id = c[e].type_name);
                        0 == r[a].cost ? r[a].cost = "免费" : r[a].cost = "￥" + r[a].cost, r[a].yestoday = app.yestoday(r[a].start_time);
                    }
                    console.log(r), i.setData({
                        activity_list: s,
                        page: o + 1
                    });
                }
            }
        });
    },
    tabClick: function(t) {
        var a = this, e = t.currentTarget.id;
        a.data.activeIndex == e ? a.setData({
            activeIndex: 5,
            zheceng: !0
        }) : a.setData({
            activeIndex: e,
            zheceng: !1
        });
    },
    zcxiao: function(t) {
        t.currentTarget.id, this.data.activeIndex;
        this.setData({
            activeIndex: 6,
            zheceng: !0
        });
    },
    wode: function() {
        var t = this.data.db_tab;
        this.data.route == t[3].src || wx.reLaunch({
            url: t[3].src
        });
    },
    fabu: function() {
        wx.reLaunch({
            url: "../fabu/fabu"
        });
    },
    index: function() {
        var t = this.data.db_tab;
        this.data.route == t[0].src || wx.reLaunch({
            url: t[0].src
        });
    },
    classifination: function(t) {
        var a = this.data.db_tab;
        this.data.route == a[1].src || wx.reLaunch({
            url: a[1].src
        });
    },
    mine_activity: function(t) {
        var a = this.data.db_tab;
        this.data.route == a[2].src || wx.reLaunch({
            url: a[2].src
        });
    },
    type_name: function(t) {
        var a = t.currentTarget.dataset.id;
        console.log(a), this.setData({
            type_id: a,
            activity_type: "",
            start_time: "",
            page: 1,
            activity_list: [],
            activeIndex: 6,
            zheceng: !0
        }), this.activity();
    },
    avtivity_type: function(t) {
        var a = t.currentTarget.dataset.type;
        console.log(a), a = "线上活动" == a ? 1 : 2, this.setData({
            activity_type: a,
            start_time: "",
            type_id: "",
            page: 1,
            activity_list: [],
            activeIndex: 6,
            zheceng: !0
        }), this.activity();
    },
    start_time: function(t) {
        if (null == t) a = this.data.start_time; else var a = t.currentTarget.dataset.type;
        function e(t) {
            var a = new Date();
            a.setDate(a.getDate() + t);
            var e = a.getFullYear(), i = a.getMonth() + 1;
            i < 10 && (i = "0" + i);
            var c = a.getDate();
            return c < 10 && (c = "0" + c), e + "-" + i + "-" + c;
        }
        console.log(a), console.log(e(1)), a = e("今天" == a ? 0 : "明天" == a ? 1 : 2), this.setData({
            start_time: a,
            activity_type: "",
            type_id: "",
            page: 1,
            activity_list: [],
            activeIndex: 6,
            zheceng: !0
        }), this.activity();
    },
    info: function(t) {
        console.log(t);
        var a = t.currentTarget.id, e = t.currentTarget.dataset.type_name;
        wx.navigateTo({
            url: "../activeinfo/activeinfo?id=" + a + "&type_name=" + e
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        this.setData({
            start_time: "",
            activity_type: "",
            type_id: "",
            page: 1,
            activity_list: []
        });
    },
    onPullDownRefresh: function() {
        this.setData({
            start_time: "",
            activity_type: "",
            type_id: "",
            page: 1,
            activity_list: []
        }), this.activity(), wx.stopPullDownRefresh();
    },
    onReachBottom: function() {
        console.log("上拉触底"), this.activity(), console.log(this.data.page);
    }
});